package com.xh.bussiness.system.controller;

import com.xh.bussiness.system.bean.request.PublicSchoolRequest;
import com.xh.bussiness.system.model.PublicSchool;
import com.xh.bussiness.system.service.IPublicSchoolService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.bean.XhPage;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.controller.BaseController;
import com.xh.core.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/admin/publicSchool")
public class PublicSchoolController extends BaseController {

    @Autowired
    private IPublicSchoolService publicSchoolService;

    /**
     * 分页数据查询
     * @param page 分页对象
     * @param bean 查询条件Bean
     * @return
     */
    @RequestMapping("/queryPage")
    public XhPage queryPage(XhPage page, PublicSchoolRequest bean){
        page=publicSchoolService.queryPublicSchoolPage(page,bean);
        return page;
    }

    @RequestMapping("/queryAll")
    public AjaxResult queryAll(PublicSchoolRequest bean) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, publicSchoolService.queryPublicSchoolAll(bean));
    }


    /**
     * 新增和保存
     * @param school 实体对象
     * @return
     */
    @RequestMapping(value="/saveOrUpdate")
    @Transactional
    public AjaxResult saveOrUpdate(@Validated PublicSchool school){
        if (StringUtils.isEmpty(school.getId())) {
            publicSchoolService.insert(school);
        } else {
            publicSchoolService.update(school);
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }

    /**
     * 批量删除操作
     * @param ids
     * @return
     */
    @RequestMapping("/batchDelete")
    @Transactional
    public AjaxResult batchDelete(String[] ids){
        publicSchoolService.batchDelete(ids);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }


    @RequestMapping("/batchChangeStatus")
    @Transactional
    public AjaxResult batchChangeStatus(String[] ids, Integer status) {
        publicSchoolService.batchChangeStatus(ids, status);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }


}
